<?php

/**
 * 新闻表
 */
class news_info extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'news_info';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('id,cn_title,cn_body,en_title,en_body,time,list_img_url,list_img_type,type_id,img_url', 'safe'),
		);
	}
	/**
	 * 通过id返回相应数据
	 * @param        $id
	 * @param string $lang
	 *
	 * @return mixed
	 */
	function getData($id,$type_id,$lang=''){
		if($id>0){$where=" and `id`='$id'";}
		if($type_id>0){$where=" and `type_id`='$type_id'";}
		if($lang=='en'){
			$sql="SELECT *,`en_title` as `title_name`,`en_body` as `body_name` FROM `".$this->tableName()."` WHERE 1=1 $where ORDER BY `type_id` ASC  LIMIT 1";
		}else{
			$sql="SELECT *,`cn_title` as `title_name`,`cn_body` as `body_name` FROM `".$this->tableName()."` WHERE 1=1 $where ORDER BY `type_id` ASC   LIMIT 1 ";
		}
		$data=news_info::getDbConnection()->createCommand($sql)->queryAll();
		return $data;
	}




}
